/*
 * sgc_chat_connections.h
 *
 *  Created on: 2011-7-11
 *      Author: rendong
 */

#ifndef SGC_CHAT_CONNECTIONS_H_
#define SGC_CHAT_CONNECTIONS_H_

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include<sys/epoll.h>
#include <sys/types.h>

#include "../core/sgc_config.h"
#include "../core/sgc_log.h"
#include "../core/sgc_inthash.h"
#include "../os/sgc_epoll.h"

// 定义全局变量
extern sgc_inthash_table_t * sgc_all_sessions; //  fd => session

// 类型定义
typedef struct _sgc_chat_session_s{
	int fd;
	struct sockaddr_in *clientaddr;
	sgc_epoll_socketserver_config_t const * config;

	char * buffer;
	int bufferpos;
	int buffersize;
}sgc_chat_session_t;


void chat_client_new_handler(int fd, struct sockaddr_in *clientaddr,  sgc_epoll_socketserver_config_t const* config);
void chat_client_message_handler(int fd, char const * buffer, int length);
void chat_client_close_hander(int fd);

void sgc_start_chat_server();

#endif /* SGC_CHAT_CONNECTIONS_H_ */
